package edu.mercer.sse.plainpdf;

import static com.google.common.base.Preconditions.*;
import edu.mercer.sse.annotations.Fulfills;

/**
 * Details from execution of command line utility.<p>
 * 
 * Provide storage for attributes of command execution: return code, output.<p>
 * 
 * @see ExecutionReporting
 */

public class ExecutionReport implements ExecutionReporting 
{
	/** StringBuilder - contains output from execution */
	
	private final StringBuilder _output = new StringBuilder();

	
	/** 
	 * Integer - return code from execution.<p>
	 * 
	 * Initialized to <code>Integer.MIN_VALUE</code><p> 
	 */
	
	private Integer _returnCode = Integer.MIN_VALUE;
	
	
	@Fulfills("ExecutionReporting")
	@Override
	public String getOutput() 
	{
		return _output.toString();
		
	}//method
	
	
	@Fulfills("ExecutionReporting")
	@Override
	public ExecutionReporting setOutput( final String output ) 
	{
		_output.setLength(0);
		
		_output.append(output);
		
		return this;
		
	}//method
	

	@Fulfills("ExecutionReporting")	
	@Override
	public ExecutionReporting appendOutput( final String output ) 
	{
		_output.append( output );
		
		return this;
		
	}//method
	
	
	@Fulfills("ExecutionReporting")
	@Override
	public Integer getReturnCode() 
	{
		return _returnCode;
		
	}//method
	
	
	@Fulfills("ExecutionReporting")
	@Override
	public ExecutionReporting setReturnCode( final Integer rc ) 
	{
		checkNotNull( rc, "null return code" );
		
		_returnCode = rc;

		return this;
		
	}//method

	
	@Fulfills("Object")
	@Override	
	public String toString()
	{
		return getOutput();
		
	}//method

	
}//class
